package com.unittec.zk.provider.exam.controller;

import com.alibaba.fastjson.JSON;
import com.unittec.zk.provider.exam.service.ElUserExamService;
import com.unittec.zk.provider.log.Log;
import com.unittec.zk.provider.utils.ValidationUtils;
import com.unittec.zk.sdk.exam.request.Req201051;
import com.unittec.zk.sdk.exam.response.Res201000;
import com.unittec.zk.sdk.log.enums.LogOperateEnum;
import com.unittec.zk.sdk.log.enums.LogStatusEnum;
import com.unittec.zk.sdk.root.domain.GatewayRequest;
import com.unittec.zk.sdk.root.domain.Result;
import com.unittec.zk.sdk.root.enums.BizCode;
import com.unittec.zk.sdk.root.enums.BizCodeEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@Api(tags = "我的考试成绩")
public class ElUserExam {

    @Resource
    private Log log;

    @Resource
    private ElUserExamService userExamService;



    /**
     * 我的成绩-分页查找
     * @param req
     * @return
     */
    @RequestMapping(value = "/201051", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "我的成绩-分页", notes = "我的成绩-分页")
    public Result<Res201000> getMyPaging(@RequestBody GatewayRequest<Req201051> req) {
        log.debug(req, "getMyPaging {}  ", "begin");
        long startLogTime = System.currentTimeMillis();
        BizCodeEnum bizCodeEnum = BizCode.ERROR;
        Res201000 res201000 = null;
        try {
            ValidationUtils.validateEntityStr(req.getContent());
            Object o = userExamService.getUserExamPage(req.getContent());
            res201000 = new Res201000();
            res201000.setObject(o);
            bizCodeEnum = BizCode.SUCCESS;
        } catch (Exception e) {
            log.error(req, e.toString(), e);
            log.addOperateLog("201051", JSON.toJSONString(req), "我的成绩-分页", log.buildErrmsg(e),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.ERROR.getCode(), startLogTime);
            return Result.error(req, e.getMessage());
        }
        log.debug(req, "getMyPaging {}  ", "end");
        if (bizCodeEnum == BizCode.SUCCESS) {
            log.addOperateLog("201051", JSON.toJSONString(req), "我的成绩-分页", bizCodeEnum.getMessage(),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.SUCCESS.getCode(), startLogTime);
            return Result.success(req, res201000);
        } else {
            log.addOperateLog("201051", JSON.toJSONString(req), "我的成绩-分页", bizCodeEnum.getMessage(),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.ERROR.getCode(), startLogTime);
            return Result.error(req, bizCodeEnum);
        }
    }
}
